package com.eugene.ui.views.property;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

import com.eugene.element.FnCalendar;
import com.eugene.entity.CommonEntity;
import com.eugene.entity.MarketVariableDAO;
import com.eugene.entity.Scenario;
import com.eugene.enums.EMaturity;

import de.ralfebert.rcputils.builder.table.ColumnBuilder;
import de.ralfebert.rcputils.builder.table.TableViewerBuilder;

public class ScenarioLabelSection extends AbstractPropertySection{
	private Text labelText;
	private Scenario sce;
	private TableViewer tableViewer;

//    private ModifyListener listener = new ModifyListener() {
//
//        public void modifyText(ModifyEvent arg0) {
//            ButtonElementProperties properties = (ButtonElementProperties) buttonElement
//                .getAdapter(IPropertySource.class);
//            properties.setPropertyValue(ButtonElementProperties.PROPERTY_TEXT,
//                labelText.getText());
//        }
//    };

    public void setInput(IWorkbenchPart part, ISelection selection) {
        super.setInput(part, selection);
        Object input = ((IStructuredSelection) selection).getFirstElement();
        this.sce = (Scenario) input;
    	FnCalendar bDate = new FnCalendar(2010,4,31);
//    	tableViewer.setInput();
    	
    }

    public void createControls(Composite parent,TabbedPropertySheetPage aTabbedPropertySheetPage) {
        super.createControls(parent, aTabbedPropertySheetPage);
        
		TableViewerBuilder t = new TableViewerBuilder(parent);

		ColumnBuilder baseDate = t.createColumn("BaseDate");
		baseDate.bindToProperty("baseDate");
//		baseDate.setPercentWidth(60);
		baseDate.useAsDefaultSortColumn();
		baseDate.makeEditable();
		baseDate.build();
		
		
		ColumnBuilder ircId = t.createColumn("IrcId");
		ircId.bindToProperty("etyId");
//		ircId.setPercentWidth(60);
//		ircId.useAsDefaultSortColumn();
		ircId.makeEditable();
		ircId.build();
		
		ColumnBuilder maturity = t.createColumn("Maturity");
		maturity.bindToProperty("maturity");
//		maturity.setPercentWidth(60);
//		maturity.useAsDefaultSortColumn();
		maturity.makeEditable();
		maturity.build();
		
		ColumnBuilder intRate = t.createColumn("IntRate");
		intRate.bindToProperty("primaryValue");
		intRate.setPercentWidth(60);
//		intRate.useAsDefaultSortColumn();
		intRate.makeEditable();
		intRate.build();
		
//		this.setInput(getPart(), getSelection());
//		if(ety == null){
//			System.out.println("11Ety is null");
//		}
//		else System.out.println("11 Ety is not null");
		FnCalendar bDate = new FnCalendar(2010,4,31);
		List list = new ArrayList();
		t.setInput(list);
//		t.setInput(MarketVariableDAO.getHistoryData(ety.getEtyId(),EMaturity.Y01,bDate,10));
		
//		t.setInput(MarketVariableDAO.getHistoryData("IRKRW_AAA",EMaturity.Y01,bDate,10));
		
		tableViewer = t.getTableViewer();
		System.out.println("End of Create Control");
        
//        Composite composite = getWidgetFactory().createFlatFormComposite(parent);
//        FormData data;
//        System.out.println("Test 4: Create Control");
//        labelText = getWidgetFactory().createText(composite, ""); //$NON-NLS-1$
//        data = new FormData();
//        data.left = new FormAttachment(0, STANDARD_LABEL_WIDTH);
//        data.right = new FormAttachment(100, 0);
//        data.top = new FormAttachment(0, ITabbedPropertyConstants.VSPACE);
//        labelText.setLayoutData(data);
////        labelText.addModifyListener(listener);
//
//        CLabel labelLabel = getWidgetFactory()
//            .createCLabel(composite, "Label:"); //$NON-NLS-1$
//        data = new FormData();
//        data.left = new FormAttachment(0, 0);
//        data.right = new FormAttachment(labelText,
//            -ITabbedPropertyConstants.HSPACE);
//        data.top = new FormAttachment(labelText, 0, SWT.CENTER);
//        labelLabel.setLayoutData(data);
    }

    public void refresh() {
//        labelText.removeModifyListener(listener);
//        ButtonElementProperties properties = (ButtonElementProperties) buttonElement
//            .getAdapter(IPropertySource.class);
//        labelText.setText(properties.strText);
//        labelText.addModifyListener(listener);
    }
}
